import Vue from 'vue'
import Vuex from 'vuex'
import axios from 'axios'

Vue.use(Vuex)

const state = {
  // 音乐播放地址
  url: '',
}

const mutations = {
  changeUrl(state, url) {
    state.url = url
  },
}

const actions = {
  async getPlayUrl(context, id) {
    const res = await axios.get('https://autumnfish.cn/song/url', {
      params: {
        id,
      },
    })
    let url = res.data.data[0].url
    context.commit('changeUrl', url)
  },
}

const getters = {}

const store = new Vuex.Store({
  state,
  mutations,
  actions,
  getters,
})

export default store
